﻿<%@ WebHandler Language="C#" Class="EmployeeWorktimeReport" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class EmployeeWorktimeReport : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESCommonMethod cm = new uMESCommonMethod();
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    private uMESWorkTimeReportBusiness wipDll = new uMESWorkTimeReportBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //查询员工信息
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetEmpInfo")
        {
            string sql = @" SELECT e.employeeid,e.employeename,e.fullname,f.factoryname,f.factoryid,
                                   w.workcentername,w.workcenterid,t.teamname,t.teamid,rd.rolename
                            FROM employee e
                            LEFT JOIN Sessionvalues sv ON sv.employeeid = e.employeeid
                            LEFT JOIN factory f ON f.factoryid = sv.factoryid
                            LEFT JOIN Workcenter w ON w.workcenterid = sv.workcenterid
                            LEFT JOIN teamemployee te ON te.employeeid = e.employeeid
                            LEFT JOIN team t ON t.teamid = te.teamid
                            LEFT JOIN employeerole er ON er.employeeid = e.employeeid
                            LEFT JOIN Roledef rd ON rd.roleid = er.roleid
                            WHERE 1=1  ";
            sql += string.Format(" AND e.employeeid = '{0}' ", context.Request.Form["uid"]);
            DataTable dt = dal.GetDataTable(sql);

            DataTable dtResult = dt.DefaultView.ToTable(true,
                "employeeid", "employeename", "fullname", "factoryname", "factoryid",
                "workcentername", "workcenterid", "teamname", "teamid");

            dtResult.Columns.Add("ROLENAME", typeof(string));

            foreach (DataRow dr in dtResult.Rows)
            {
                if (dt.Select("rolename='定额员'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }

                if (dt.Select("rolename='系统管理员'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }

                if (dt.Select("rolename='分厂领导'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }

                if (dr["factoryname"].ToString() == "")
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }

                if (dt.Select("rolename='工区长'").Length > 0)
                {
                    if (dr["workcentername"].ToString() == "")
                    {
                        dr["ROLENAME"] = "管理员";
                        break;
                    }
                    else
                    {
                        dr["ROLENAME"] = "工区长";
                        break;
                    }
                }

                if (dt.Select("rolename='班组长'").Length > 0)
                {
                    if (dr["teamname"].ToString() == "")
                    {
                        if (dr["workcentername"].ToString() == "")
                        {
                            dr["ROLENAME"] = "管理员";
                            break;
                        }
                        else
                        {
                            dr["ROLENAME"] = "工区长";
                            break;
                        }
                    }
                    else
                    {
                        dr["ROLENAME"] = "班组长";
                        break;
                    }
                }

                if (dt.Select("rolename='工人'").Length > 0)
                {
                    dr["ROLENAME"] = "工人";
                    break;
                }
            }

            var json = JsonConvert.SerializeObject(dtResult);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询机型
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetProductFamily")
        {
            DataTable dt = cm.GetProductFamily();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询分厂
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetFactory")
        {
            //只查询机匣、结构件、盘轴、燃烧
            string sql = "SELECT f.factoryname,f.factoryid FROM factory f WHERE f.factoryid IN ('0004e2800000001c','0004e28000000dc6','0004e28000002582','0004e28000000dc0')";
            DataTable dt = dal.GetDataTable(sql);
            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询工区
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenter")
        {
            string factoryid = context.Request.Form["factoryid"].ToString();
            string sql = string.Format("SELECT w.workcenterid,w.workcentername FROM workcenter w WHERE w.notes is null and w.factoryid = '{0}'", factoryid);
            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询组（Team）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetTeam")
        {
            string factoryid = context.Request.Form["factoryid"].ToString();
            string sql = @"SELECT t.teamid,t.teamname
                           FROM team t 
                           LEFT JOIN Workcenter w ON w.workcenterid = t.workcenterid
                           LEFT JOIN factory f ON f.factoryid = w.factoryid
                           WHERE 1=1 ";

            sql += string.Format(" AND w.factoryid = '{0}'", factoryid);

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND w.workcenterid = '{0}'", context.Request.Form["workcenterid"]);
            }

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询员工（Team）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetEmp")
        {
            string factoryid = context.Request.Form["factoryid"].ToString();
            string sql = @" SELECT distinct e.employeeid,e.employeename,e.fullname
                            FROM employee e
                            LEFT JOIN Sessionvalues sv ON sv.employeeid = e.employeeid
                            LEFT JOIN teamemployee te ON te.employeeid = e.employeeid
                            LEFT JOIN team t ON t.teamid = te.teamid
                            WHERE 1=1 ";

            sql += string.Format(" AND sv.factoryid = '{0}'", factoryid);

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND sv.workcenterid = '{0}'", context.Request.Form["workcenterid"]);
            }
            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "")
            {
                sql += string.Format(" AND t.teamid = '{0}'", context.Request.Form["teamid"]);
            }

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkTimeDate")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null && context.Request.Form["factoryid"] != "空")
            {
                para["factoryid"] = context.Request.Form["factoryid"];
            }

            int worktimeday = wipDll.GetMonthWorkTimeDay(para);

            string CheckDateStart, CheckDateEnd;
            if (DateTime.Now.Day > worktimeday)
            {
                CheckDateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, worktimeday).ToShortDateString();
            }
            else
            {
                // 当前日期不为节点日期，且月份不为1月时,检验日期文本框置为上月节点日期
                if (DateTime.Now.Month != 1)
                {
                    CheckDateStart = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, worktimeday).ToShortDateString();
                }
                else
                {
                    // 当前日期不为节点日期，且月份为1月时,检验日期文本框置为上一年12月节点日期
                    CheckDateStart = new DateTime(DateTime.Now.Year - 1, 12, worktimeday).ToShortDateString();
                }
            }

            // 检验结束时间默认取当前时间
            CheckDateEnd = DateTime.Now.ToShortDateString();

            var json = "{\"CheckDateStart\":\"" + CheckDateStart + "\",\"CheckDateEnd\":\"" + CheckDateEnd + "\"}";
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询工时
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkTime")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null && context.Request.Form["factoryid"] != "空")
            {
                para["factoryid"] = context.Request.Form["factoryid"];
            }
            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.Form["workcenterid"];
            }
            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "空")
            {
                para["teamid"] = context.Request.Form["teamid"];
            }
            if (context.Request.Form["employeeid"] != null && context.Request.Form["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.Form["employeeid"];
            }
            if (context.Request.Form["productname"] != null && context.Request.Form["productname"] != "空")
            {
                para["productname"] = context.Request.Form["productname"];
            }
            if (context.Request.Form["productfamilyname"] != null && context.Request.Form["productfamilyname"] != "空")
            {
                para["productfamilyname"] = context.Request.Form["productfamilyname"];
            }
            if (context.Request.Form["CheckDateStart"] != null)
            {
                para["CheckDateStart"] = context.Request.Form["CheckDateStart"] + " 00:00:00";
            }
            if (context.Request.Form["CheckDateEnd"] != null)
            {
                para["CheckDateEnd"] = context.Request.Form["CheckDateEnd"] + " 23:59:59";
            }
            if (context.Request.Form["status"] != null && context.Request.Form["status"] != "空")
            {
                para["status"] = context.Request.Form["status"];
            }
            para["worktimeday"] = 19;

            DataTable dtResult = wipDll.GetEmployeeWorkTime(para);

            foreach (DataColumn col in dtResult.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            var json = JsonConvert.SerializeObject(dtResult);

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + dtResult.Rows.Count
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //工时明细
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkTimeDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null && context.Request.Form["factoryid"] != "空")
            {
                para["factoryid"] = context.Request.Form["factoryid"];
            }
            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.Form["workcenterid"];
            }
            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "空")
            {
                para["teamid"] = context.Request.Form["teamid"];
            }
            if (context.Request.Form["employeeid"] != null && context.Request.Form["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.Form["employeeid"];
            }
            if (context.Request.Form["productname"] != null && context.Request.Form["productname"] != "空")
            {
                para["productname"] = context.Request.Form["productname"];
            }
            if (context.Request.Form["productfamilyname"] != null && context.Request.Form["productfamilyname"] != "空")
            {
                para["productfamilyname"] = context.Request.Form["productfamilyname"];
            }
            if (context.Request.Form["CheckDateStart"] != null)
            {
                para["CheckDateStart"] = context.Request.Form["CheckDateStart"] + " 00:00:00";
            }
            if (context.Request.Form["CheckDateEnd"] != null)
            {
                para["CheckDateEnd"] = context.Request.Form["CheckDateEnd"] + " 23:59:59";
            }
            if (context.Request.Form["status"] != null && context.Request.Form["status"] != "空")
            {
                para["status"] = context.Request.Form["status"];
            }
            para["worktimeday"] = 19;

            if (context.Request.Form["page"] != null)
            {
                para["intPage"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["pageSize"] = context.Request.Form["rows"].ToString();
            }

            int pagecount = 0;
            int rowCount = 0;
            DataTable dtWorkTimeDetails = wipDll.GetEmployeeWorkTimeDetails(para, out pagecount, out rowCount);

            foreach (DataColumn col in dtWorkTimeDetails.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            var json = JsonConvert.SerializeObject(dtWorkTimeDetails);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //导出前判断是否为空表
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetIsEmpty")
        {
            DataTable dtSum = new DataTable();
            var json = JsonConvert.SerializeObject(dtSum);

            json = "{\"count\":" + dtSum.Rows.Count + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //导出
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "print")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null && context.Request.QueryString["factoryid"] != "空")
            {
                para["factoryid"] = context.Request.QueryString["factoryid"];
            }
            if (context.Request.QueryString["workcenterid"] != null && context.Request.QueryString["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.QueryString["workcenterid"];
            }
            if (context.Request.QueryString["teamid"] != null && context.Request.QueryString["teamid"] != "空")
            {
                para["teamid"] = context.Request.QueryString["teamid"];
            }
            if (context.Request.QueryString["employeeid"] != null && context.Request.QueryString["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.QueryString["employeeid"];
            }
            if (context.Request.QueryString["productname"] != null && context.Request.QueryString["productname"] != "空")
            {
                para["productname"] = context.Request.QueryString["productname"];
            }
            if (context.Request.QueryString["productfamilyname"] != null && context.Request.QueryString["productfamilyname"] != "空")
            {
                para["productfamilyname"] = context.Request.QueryString["productfamilyname"];
            }
            if (context.Request.QueryString["CheckDateStart"] != null)
            {
                para["CheckDateStart"] = context.Request.QueryString["CheckDateStart"] + " 00:00:00";
            }
            if (context.Request.QueryString["CheckDateEnd"] != null)
            {
                para["CheckDateEnd"] = context.Request.QueryString["CheckDateEnd"] + " 23:59:59";
            }
            if (context.Request.QueryString["status"] != null && context.Request.QueryString["status"] != "空")
            {
                para["status"] = context.Request.QueryString["status"];
            }
            para["worktimeday"] = 19;

            DataTable dtMain = wipDll.GetEmployeeWorkTime(para);

            DataTable dtChild = wipDll.ExportEmployeeWorkTime(para);

            DataTable dtResult = new DataTable("MainChild");
            //主表字段
            dtResult.Columns.Add("RN");//编号
            dtResult.Columns.Add("fullname");
            dtResult.Columns.Add("employeename");
            dtResult.Columns.Add("employeeworktime");
            dtResult.Columns.Add("employeeCurrentMonthWorkTime");

            //子表字段
            dtResult.Columns.Add("mfgordername");
            dtResult.Columns.Add("containername");
            dtResult.Columns.Add("specname");
            dtResult.Columns.Add("qty");
            dtResult.Columns.Add("workcentername");
            dtResult.Columns.Add("reporttime");
            dtResult.Columns.Add("checkDate");      // add zhunan 2018.8.28
            dtResult.Columns.Add("durationperunit"); // add zhunan 2018.5.3
            dtResult.Columns.Add("worktime");
            dtResult.Columns.Add("isSubmit");
            dtResult.Columns.Add("isHeXiao");
            dtResult.Columns.Add("isHeSuan");

            //主表字段标题设置
            dtResult.Columns["RN"].Caption = "序号";
            dtResult.Columns["fullname"].Caption = "员工";
            dtResult.Columns["employeename"].Caption = "工号";
            dtResult.Columns["employeeworktime"].Caption = "个人工时（小时）";
            dtResult.Columns["employeeCurrentMonthWorkTime"].Caption = "当月工时（小时）";

            //子表字段标题
            dtResult.Columns["mfgordername"].Caption = "订单号";
            dtResult.Columns["containername"].Caption = "批次号";
            dtResult.Columns["specname"].Caption = "工序";
            dtResult.Columns["qty"].Caption = "数量";
            dtResult.Columns["workcentername"].Caption = "工区";
            dtResult.Columns["reporttime"].Caption = "报工时间";
            dtResult.Columns["checkDate"].Caption = "检验日期";             // add zhunan 2018.8.28
            dtResult.Columns["durationperunit"].Caption = "单位工时（分）"; // add zhunan 2018.5.3
            dtResult.Columns["worktime"].Caption = "合计工时（分）";
            dtResult.Columns["isSubmit"].Caption = "是否已提交";
            dtResult.Columns["isHeXiao"].Caption = "是否已核销";
            dtResult.Columns["isHeSuan"].Caption = "是否已核算";
            DataRow newRow;
            int count = 0;
            for (int i = 0; i < dtMain.Rows.Count; i++)
            {

                DataRow[] row = dtChild.Select("employeeid ='" + dtMain.Rows[i]["employeeid"].ToString() + "'");
                for (int j = 0; j < row.Length; j++)
                {
                    newRow = dtResult.NewRow();
                    //主表字段值
                    newRow["RN"] = ++count;
                    newRow["fullname"] = dtMain.Rows[i]["fullname"].ToString();
                    newRow["employeename"] = dtMain.Rows[i]["employeename"].ToString();
                    newRow["employeeworktime"] = dtMain.Rows[i]["employeeworktime"].ToString();
                    newRow["employeeCurrentMonthWorkTime"] = dtMain.Rows[i]["employeeCurrentMonthWorkTime"].ToString();

                    // 子表字段值
                    newRow["mfgordername"] = row[j]["mfgordername"].ToString();
                    newRow["containername"] = row[j]["containername"].ToString();
                    newRow["specname"] = row[j]["specname"].ToString();
                    newRow["qty"] = row[j]["qty"].ToString();
                    newRow["workcentername"] = row[j]["workcentername"].ToString();
                    newRow["reporttime"] = row[j]["reporttime"].ToString();
                    newRow["checkDate"] = row[j]["checkDate"].ToString(); // add zhunan 2018.8.28
                    newRow["durationperunit"] = row[j]["durationperunit"].ToString(); // add zhunan 2018.5.3
                    newRow["worktime"] = row[j]["sumworktime"].ToString();
                    newRow["isSubmit"] = row[j]["isSubmit"].ToString();
                    newRow["isHeXiao"] = row[j]["isHeXiao"].ToString();
                    newRow["isHeSuan"] = row[j]["isHeSuan"].ToString();
                    dtResult.Rows.Add(newRow);
                }
            }

            // 结构件分厂导出时隐藏当月工时信息 add zhunan 2018.03.29
            if (para["factoryid"].ToString() == "0004e28000000dc6")
            {
                dtResult.Columns.Remove("employeeCurrentMonthWorkTime");
            }

            ExportHelper.ExportExcel(dtResult, "工时统计报表");
        }

        //导出
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "loading")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null && context.Request.QueryString["factoryid"] != "空")
            {
                para["factoryid"] = context.Request.QueryString["factoryid"];
            }
            if (context.Request.QueryString["workcenterid"] != null && context.Request.QueryString["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.QueryString["workcenterid"];
            }
            if (context.Request.QueryString["teamid"] != null && context.Request.QueryString["teamid"] != "空")
            {
                para["teamid"] = context.Request.QueryString["teamid"];
            }
            if (context.Request.QueryString["employeeid"] != null && context.Request.QueryString["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.QueryString["employeeid"];
            }
            if (context.Request.QueryString["productname"] != null && context.Request.QueryString["productname"] != "空")
            {
                para["productname"] = context.Request.QueryString["productname"];
            }
            if (context.Request.QueryString["productfamilyname"] != null && context.Request.QueryString["productfamilyname"] != "空")
            {
                para["productfamilyname"] = context.Request.QueryString["productfamilyname"];
            }
            if (context.Request.QueryString["CheckDateStart"] != null)
            {
                para["CheckDateStart"] = context.Request.QueryString["CheckDateStart"] + " 00:00:00";
            }
            if (context.Request.QueryString["CheckDateEnd"] != null)
            {
                para["CheckDateEnd"] = context.Request.QueryString["CheckDateEnd"] + " 23:59:59";
            }
            if (context.Request.QueryString["status"] != null && context.Request.QueryString["status"] != "空")
            {
                para["status"] = context.Request.QueryString["status"];
            }
            para["worktimeday"] = 19;

            DataTable dtMain = wipDll.GetEmployeeWorkTime(para);

            DataTable dtChild = wipDll.ExportEmployeeWorkTime(para);

            DataTable dtResult = new DataTable("MainChild");
            //主表字段
            dtResult.Columns.Add("RN");//编号
            dtResult.Columns.Add("fullname");
            dtResult.Columns.Add("employeename");
            dtResult.Columns.Add("employeeworktime");
            dtResult.Columns.Add("employeeCurrentMonthWorkTime");

            //子表字段
            dtResult.Columns.Add("mfgordername");
            dtResult.Columns.Add("containername");
            dtResult.Columns.Add("specname");
            dtResult.Columns.Add("qty");
            dtResult.Columns.Add("workcentername");
            dtResult.Columns.Add("reporttime");
            dtResult.Columns.Add("checkDate");      // add zhunan 2018.8.28
            dtResult.Columns.Add("durationperunit"); // add zhunan 2018.5.3
            dtResult.Columns.Add("worktime");
            dtResult.Columns.Add("isSubmit");
            dtResult.Columns.Add("isHeXiao");
            dtResult.Columns.Add("isHeSuan");

            //主表字段标题设置
            dtResult.Columns["RN"].Caption = "序号";
            dtResult.Columns["fullname"].Caption = "员工";
            dtResult.Columns["employeename"].Caption = "工号";
            dtResult.Columns["employeeworktime"].Caption = "个人工时（小时）";
            dtResult.Columns["employeeCurrentMonthWorkTime"].Caption = "当月工时（小时）";

            //子表字段标题
            dtResult.Columns["mfgordername"].Caption = "订单号";
            dtResult.Columns["containername"].Caption = "批次号";
            dtResult.Columns["specname"].Caption = "工序";
            dtResult.Columns["qty"].Caption = "数量";
            dtResult.Columns["workcentername"].Caption = "工区";
            dtResult.Columns["reporttime"].Caption = "报工时间";
            dtResult.Columns["checkDate"].Caption = "检验日期";             // add zhunan 2018.8.28
            dtResult.Columns["durationperunit"].Caption = "单位工时（分）"; // add zhunan 2018.5.3
            dtResult.Columns["worktime"].Caption = "合计工时（分）";
            dtResult.Columns["isSubmit"].Caption = "是否已提交";
            dtResult.Columns["isHeXiao"].Caption = "是否已核销";
            dtResult.Columns["isHeSuan"].Caption = "是否已核算";
            DataRow newRow;
            int count = 0;
            for (int i = 0; i < dtMain.Rows.Count; i++)
            {

                DataRow[] row = dtChild.Select("employeeid ='" + dtMain.Rows[i]["employeeid"].ToString() + "'");
                for (int j = 0; j < row.Length; j++)
                {
                    newRow = dtResult.NewRow();
                    //主表字段值
                    newRow["RN"] = ++count;
                    newRow["fullname"] = dtMain.Rows[i]["fullname"].ToString();
                    newRow["employeename"] = dtMain.Rows[i]["employeename"].ToString();
                    newRow["employeeworktime"] = dtMain.Rows[i]["employeeworktime"].ToString();
                    newRow["employeeCurrentMonthWorkTime"] = dtMain.Rows[i]["employeeCurrentMonthWorkTime"].ToString();

                    // 子表字段值
                    newRow["mfgordername"] = row[j]["mfgordername"].ToString();
                    newRow["containername"] = row[j]["containername"].ToString();
                    newRow["specname"] = row[j]["specname"].ToString();
                    newRow["qty"] = row[j]["qty"].ToString();
                    newRow["workcentername"] = row[j]["workcentername"].ToString();
                    newRow["reporttime"] = row[j]["reporttime"].ToString();
                    newRow["checkDate"] = row[j]["checkDate"].ToString(); // add zhunan 2018.8.28
                    newRow["durationperunit"] = row[j]["durationperunit"].ToString(); // add zhunan 2018.5.3
                    newRow["worktime"] = row[j]["sumworktime"].ToString();
                    newRow["isSubmit"] = row[j]["isSubmit"].ToString();
                    newRow["isHeXiao"] = row[j]["isHeXiao"].ToString();
                    newRow["isHeSuan"] = row[j]["isHeSuan"].ToString();
                    dtResult.Rows.Add(newRow);
                }
            }

            var json = ""; ;
            context.Response.ContentType = "text/json";

            json = "{\"data\":[]"
                    + ",\"count\":" + dtResult.Rows.Count
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}